<?php
/* @var $this ShiftChangeController */
/* @var $model ShiftChange */
/* @var $form CActiveForm */
?>

<div class="form" style="width:490px;">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'shift-change-form',
	'enableAjaxValidation'=>false,
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,)			
)); ?>

<center>
	<p class="note">Fields with <span class="required">*</span> are required.</p>
	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php
			$now = new DateTime("tomorrow");
		
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
				'model' => $model,
				'attribute' => 'day_requested',
				'themeUrl' => Yii::app()->baseUrl . '/css/jui',
				'theme' => 'start',
				'cssFile' => 'jquery-ui-1.10.3.custom.css',		
				 'options' => array(
						'showOn' => 'both',             // also opens with a button
						'dateFormat' => 'yy-mm-dd',     // format of "2012-12-25"
						'showOtherMonths' => true,      // show dates in other months
						//'selectOtherMonths' => true,    // can select dates in other months
						//'changeYear' => true,           // can change year
						//'changeMonth' => true,          // can change month
						'yearRange' => '2013:2020',     // range of year
						'minDate' => $now->format('Y-m-d'),      // minimum date
						'maxDate' => '2020-12-31',      // maximum date
						//'showButtonPanel' => true,      // show button panel
	
					),				
				'htmlOptions' => array(
					'size' => '10',        
					'maxlength' => '10',  
				),
			));				
		?>
		<?php echo $form->error($model,'day_requested'); ?>
	</div>

<table style="width:350px;">

	<tr>
		<td  colspan=2 >
			<div class="row compactRadioGroup">
			<?php echo CHtml::radioButtonList('choice',
											  'radioToShift',
											  array('radioToShift'=>'Direct Change',
													'radioToUser'=>'Change with User'),
											  array('separator' => '&nbsp&nbsp&nbsp|&nbsp&nbsp&nbsp&nbsp',
													'onclick'=>'radioToggle()'
													)
											  ); ?>
			</div>
		</td>
	</tr>
	
	<tr>
		<td >
		<div class="row">
				<?php echo $form->labelEx($model,'requested_shift'); ?>
					<?php echo $form->dropDownList($model,'requested_shift',
												   CHtml::listData(Shift::model()->findAll(array('condition'=>'team_id = '.$model->team_id.' and enabled = 1', 'order'=>'start_time ASC')),
																   'idshift', 
																   'name',
																   'start_time'),	
													array('empty'=>'','class'=>'dropshift','style'=>'visibility:visible;'));?>
				<?php echo $form->error($model,'requested_shift'); ?>
			</div>

			<div class="row" >
				<?php echo $form->labelEx($model,'requested_qshift'); ?>
					<?php echo $form->dropDownList($model,'requested_qshift',
												   CHtml::listData(Qshift::model()->findAll(array('condition'=>'team_id = '.$model->team_id.' and enabled = 1', 'order'=>'start_time ASC')),
																   'idqshift', 
																   'name'),	
													array('empty'=>'','class'=>'dropshift','style'=>'visibility:visible;'));?>		
				<?php echo $form->error($model,'requested_qshift'); ?>
			</div>
		</td>
		
		<td  >
			<div class="row">
				<?php echo $form->labelEx($model,'target_user'); ?>
					<?php echo $form->dropDownList($model,'target_user',
												   CHtml::listData(User::model()->findAll(array('condition'=>'team = '.$model->team_id, 'order'=>'username ASC')),
																   'iduser', 
																   'fullname'),	
													array('empty'=>'',
														  'class'=>'dropfullname',
														  'style'=>'visibility:hidden;',
														  'ajax' => array(
																		'type' => 'GET',
																		'url' => CController::createUrl('shiftChange/ajaxTargetShiftLoader'),
																		'data'=> array('target_user'=>'js: $(this).val()',
																					   'date'=>'js: $("#ShiftChange_day_requested").val()'),  
																		'update' => '#target_qshift',													
																		)												  
														  )
													);?>
				<?php echo $form->error($model,'target_user'); ?>
			</div>
			<div id='target_qshift' class='row'>

			</div>
		</td>
	</tr>
</table>

	<div class="row">
		<?php echo $form->labelEx($model,'comments'); ?>
		<?php echo $form->textArea($model,'comments',array('row'=>2,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'comments'); ?>
	</div>
	<div class="buttons">
		<?php echo CHtml::submitButton('Create'); ?>
		<?php echo CHtml::ajaxSubmitButton ('Create',
									   CController::createUrl('shiftChange/rosterCreate'), 
									   array('type' => 'GET',
											 'data'=> array('user'=>$model->requesting_user,'date'=>$model->day_requested),
											 'update' => '#leftVisor')
									);
		?>
								
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->